﻿using System;
namespace Producers.Rr.Xtee.Riik.Ee.Producer.Rr {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="VMIsikutToendavDokument", Namespace="http://producers.rr.xtee.riik.ee/producer/rr", Target=typeof(VMIsikutToendavDokument))]
    public class VMIsikutToendavDokumentSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IVMIsikutToendavDokument clazz;
        
        public VMIsikutToendavDokumentSerializer(IVMIsikutToendavDokument clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement("Isikukood");
            if (clazz.Isikukood!=null) {
                Writer.WriteTypeAttribute("http://producers.rr.xtee.riik.ee/producer/rr", "PersonalCode");
                Writer.WriteString(clazz.Isikukood.ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Isikukood");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("Perekonnanimi");
            if (clazz.Perekonnanimi!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Perekonnanimi))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Perekonnanimi");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("Eesnimi");
            if (clazz.Eesnimi!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Eesnimi))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Eesnimi");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("Tegevus");
            if (clazz.Tegevus!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Tegevus))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Tegevus");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("DokumendiLiik");
            if (clazz.DokumendiLiik!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.DokumendiLiik))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : DokumendiLiik");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("DokumendiNimetus");
            if (clazz.DokumendiNimetus!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.DokumendiNimetus))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : DokumendiNimetus");
            }
            Writer.WriteEndElement();
            if (clazz.DokumendiSeeria!=null) {
                Writer.WriteStartElement("DokumendiSeeria");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.DokumendiSeeria))).ToString());
                Writer.WriteEndElement();
            }
            Writer.WriteStartElement("DokumendiNumber");
            if (clazz.DokumendiNumber!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.DokumendiNumber))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : DokumendiNumber");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("KehtivuseAlgus");
            if (clazz.KehtivuseAlgus!=null) {
                Writer.WriteTypeAttribute("http://producers.rr.xtee.riik.ee/producer/rr", "date");
                Writer.WriteString(clazz.KehtivuseAlgus.ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : KehtivuseAlgus");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("KehtivuseLopp");
            if (clazz.KehtivuseLopp!=null) {
                Writer.WriteTypeAttribute("http://producers.rr.xtee.riik.ee/producer/rr", "date");
                Writer.WriteString(clazz.KehtivuseLopp.ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : KehtivuseLopp");
            }
            Writer.WriteEndElement();
            if (clazz.KehtetuAlates!=null) {
                Writer.WriteStartElement("KehtetuAlates");
                Writer.WriteTypeAttribute("http://producers.rr.xtee.riik.ee/producer/rr", "date");
                Writer.WriteString(clazz.KehtetuAlates.ToString());
                Writer.WriteEndElement();
            }
            Writer.WriteStartElement("AsutuseRegNr");
            if (clazz.AsutuseRegNr!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.AsutuseRegNr))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : AsutuseRegNr");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("AsutuseNimi");
            if (clazz.AsutuseNimi!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.AsutuseNimi))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : AsutuseNimi");
            }
            Writer.WriteEndElement();
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="Isikukood") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>VMIsikutToendavDokument>Isikukood");
                }
                clazz.Isikukood = new global::Producers.Rr.Xtee.Riik.Ee.Producer.Rr.PersonalCode(Reader.ReadElementString("Isikukood"));
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>VMIsikutToendavDokument>Isikukood", Reader.LocalName);
            }
            if (Reader.LocalName=="Perekonnanimi") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>VMIsikutToendavDokument>Perekonnanimi");
                }
                clazz.Perekonnanimi = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("Perekonnanimi")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>VMIsikutToendavDokument>Perekonnanimi", Reader.LocalName);
            }
            if (Reader.LocalName=="Eesnimi") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>VMIsikutToendavDokument>Eesnimi");
                }
                clazz.Eesnimi = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("Eesnimi")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>VMIsikutToendavDokument>Eesnimi", Reader.LocalName);
            }
            if (Reader.LocalName=="Tegevus") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>VMIsikutToendavDokument>Tegevus");
                }
                clazz.Tegevus = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("Tegevus")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>VMIsikutToendavDokument>Tegevus", Reader.LocalName);
            }
            if (Reader.LocalName=="DokumendiLiik") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>VMIsikutToendavDokument>DokumendiLiik");
                }
                clazz.DokumendiLiik = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("DokumendiLiik")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>VMIsikutToendavDokument>DokumendiLiik", Reader.LocalName);
            }
            if (Reader.LocalName=="DokumendiNimetus") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>VMIsikutToendavDokument>DokumendiNimetus");
                }
                clazz.DokumendiNimetus = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("DokumendiNimetus")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>VMIsikutToendavDokument>DokumendiNimetus", Reader.LocalName);
            }
            if (Reader.LocalName=="DokumendiSeeria") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>VMIsikutToendavDokument>DokumendiSeeria");
                }
                clazz.DokumendiSeeria = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("DokumendiSeeria")).Value;
            }
            if (Reader.LocalName=="DokumendiNumber") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>VMIsikutToendavDokument>DokumendiNumber");
                }
                clazz.DokumendiNumber = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("DokumendiNumber")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>VMIsikutToendavDokument>DokumendiNumber", Reader.LocalName);
            }
            if (Reader.LocalName=="KehtivuseAlgus") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>VMIsikutToendavDokument>KehtivuseAlgus");
                }
                clazz.KehtivuseAlgus = new global::Producers.Rr.Xtee.Riik.Ee.Producer.Rr.Date(Reader.ReadElementString("KehtivuseAlgus"));
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>VMIsikutToendavDokument>KehtivuseAlgus", Reader.LocalName);
            }
            if (Reader.LocalName=="KehtivuseLopp") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>VMIsikutToendavDokument>KehtivuseLopp");
                }
                clazz.KehtivuseLopp = new global::Producers.Rr.Xtee.Riik.Ee.Producer.Rr.Date(Reader.ReadElementString("KehtivuseLopp"));
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>VMIsikutToendavDokument>KehtivuseLopp", Reader.LocalName);
            }
            if (Reader.LocalName=="KehtetuAlates") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>VMIsikutToendavDokument>KehtetuAlates");
                }
                clazz.KehtetuAlates = new global::Producers.Rr.Xtee.Riik.Ee.Producer.Rr.Date(Reader.ReadElementString("KehtetuAlates"));
            }
            if (Reader.LocalName=="AsutuseRegNr") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>VMIsikutToendavDokument>AsutuseRegNr");
                }
                clazz.AsutuseRegNr = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("AsutuseRegNr")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>VMIsikutToendavDokument>AsutuseRegNr", Reader.LocalName);
            }
            if (Reader.LocalName=="AsutuseNimi") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>VMIsikutToendavDokument>AsutuseNimi");
                }
                clazz.AsutuseNimi = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("AsutuseNimi")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>VMIsikutToendavDokument>AsutuseNimi", Reader.LocalName);
            }
        }
    }
}
